﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace JukeBox
{
    public class ListColumn
    {
        public string Name { get; set; }
        public string ID { get; set; }

        private int _width;

        public int Width
        {
            get
            {
                return _width > 5 ? _width : 100;
            }
            set
            {
                _width = value;
            }
        }

        public ListColumn()
        {
            this.Width = 100;
        }

        public ListColumn(string id, string name) : this()
        {
            this.ID = id;
            this.Name = name;
        }

        public string GetValue(JukeBoxLib.Track track)
        {
            try
            {
                object tag = track.GetType().GetProperty(this.ID).GetValue(track, null);
                switch (tag.GetType().Name)
                {
                    case "TimeSpan" :
                        return ((TimeSpan)tag).ToString(@"hh\:mm\:ss");
                    default:
                        return tag.ToString();
                }
            }
            catch (Exception)
            {
                Debug.Assert(true);
            }
            return null;
        }

        public override string ToString()
        {
            return Name;
        }

    }
}
